package org.viva.action.admin;

import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.ProxoolFacade;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.viva.core.Config;

@Controller
public class InfoAction {

    @RequestMapping("/admin/info")
    public String index(ModelMap modelMap) {
        modelMap.put("info", Config.getConfig());
        modelMap.put("runtime", Runtime.getRuntime());
        long mb = 1024 * 1024;
        modelMap.put("sst1", Runtime.getRuntime().totalMemory() / mb);
        modelMap.put("sst2", Runtime.getRuntime().freeMemory() / mb);
        modelMap.put("sst3", Runtime.getRuntime().maxMemory() / mb);

        // 获得线程总数
        ThreadGroup parentThread;
        for (parentThread = Thread.currentThread().getThreadGroup(); parentThread.getParent() != null; parentThread = parentThread.getParent())
            ;
        int totalThread = parentThread.activeCount();
        modelMap.put("totalThread", totalThread);
        // modelMap.put("cached", "缓存：" + Cache.getStatus() + "");
        try {
            modelMap.put("proxool", ProxoolFacade.getSnapshot((String) Config.getConfig("jdbc.type"), true));
        } catch (ProxoolException e) {
            e.printStackTrace();
        }
        return "/admin/info";
    }

}
